package au.org.arcs.dss.provider;

import java.util.*;

import org.apache.log4j.Logger;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author ming
 */
public class ConfigManager {
  public static Logger logger;
  public static String key;
  private static ApplicationContext applicationContext;

  private boolean cacheEnabled;
  private String cacheConfigFile;
  private String cacheDir;
  private String cacheName;

  private String urlPrefix;
  private static Map<String, String> rootPaths = new HashMap<String, String>();

  private String irodsPrefix;
  private String irodsUsername;
  private String irodsPassword;
  private String irodsHost;
  private int irodsPort;
  private String irodsZone;
  private String irodsDefaultResource;

  private boolean stub;
  private String irodsRoot;
  private String tempFileFolder;

  private int batchSize;

  public ConfigManager() {
    //DOMConfigurator.configure(this.getClass().getResource("/au/org/arcs/dss/provider/dssLog4j.xml"));
    logger = Logger.getLogger(ConfigManager.class);
  }

  public static ApplicationContext getApplicationContextInstance() {
    if (applicationContext == null) {
      applicationContext = new ClassPathXmlApplicationContext("/applicationContext.xml");
    }

    return applicationContext;
  }

  public static ConfigManager getConfigManagerInstance() {
    return (ConfigManager) getApplicationContextInstance().getBean("configManager", ConfigManager.class);
  }

  public void setKey(String key) {
    ConfigManager.key = key;
  }

  /**
   * @return the rootPaths
   */
  public static Map<String, String> getRootPaths() {
    return rootPaths;
  }

  public static void setRootPath(String key, String path) {
    rootPaths.put(key, path);
  }

  public static String getRootPath(String key) {
    return rootPaths.get(key);
  }

  /**
   * @return the cacheEnabled
   */
  public boolean isCacheEnabled() {
    return cacheEnabled;
  }

  /**
   * @param cacheEnabled the cacheEnabled to set
   */
  public void setCacheEnabled(boolean cacheEnabled) {
    this.cacheEnabled = cacheEnabled;
  }

  /**
   * @return the cacheConfigFile
   */
  public String getCacheConfigFile() {
    return cacheConfigFile;
  }

  /**
   * @param cacheConfigFile the cacheConfigFile to set
   */
  public void setCacheConfigFile(String cacheConfigFile) {
    this.cacheConfigFile = cacheConfigFile;
  }

  /**
   * @return the irodsPrefix
   */
  public String getIrodsPrefix() {
    return irodsPrefix;
  }

  /**
   * @param irodsPrefix the irodsPrefix to set
   */
  public void setIrodsPrefix(String irodsPrefix) {
    this.irodsPrefix = irodsPrefix;
  }

  /**
   * @return the irodsUsername
   */
  public String getIrodsUsername() {
    return irodsUsername;
  }

  /**
   * @param irodsUsername the irodsUsername to set
   */
  public void setIrodsUsername(String irodsUsername) {
    this.irodsUsername = irodsUsername;
  }

  /**
   * @return the irodsPassword
   */
  public String getIrodsPassword() {
    return irodsPassword;
  }

  /**
   * @param irodsPassword the irodsPassword to set
   */
  public void setIrodsPassword(String irodsPassword) {
    this.irodsPassword = irodsPassword;
  }

  /**
   * @return the irodsHost
   */
  public String getIrodsHost() {
    return irodsHost;
  }

  /**
   * @param irodsHost the irodsHost to set
   */
  public void setIrodsHost(String irodsHost) {
    this.irodsHost = irodsHost;
  }

  /**
   * @return the irodsPort
   */
  public int getIrodsPort() {
    return irodsPort;
  }

  /**
   * @param irodsPort the irodsPort to set
   */
  public void setIrodsPort(int irodsPort) {
    this.irodsPort = irodsPort;
  }

  /**
   * @return the irodsZone
   */
  public String getIrodsZone() {
    return irodsZone;
  }

  /**
   * @param irodsZone the irodsZone to set
   */
  public void setIrodsZone(String irodsZone) {
    this.irodsZone = irodsZone;
  }

  /**
   * @return the irodsDefaultResource
   */
  public String getIrodsDefaultResource() {
    return irodsDefaultResource;
  }

  /**
   * @param irodsDefaultResource the irodsDefaultResource to set
   */
  public void setIrodsDefaultResource(String irodsDefaultResource) {
    this.irodsDefaultResource = irodsDefaultResource;
  }

  /**
   * @return the cacheDir
   */
  public String getCacheDir() {
    return cacheDir;
  }

  /**
   * @param cacheDir the cacheDir to set
   */
  public void setCacheDir(String cacheDir) {
    this.cacheDir = cacheDir;
  }

  /**
   * @return the cacheName
   */
  public String getCacheName() {
    return cacheName;
  }

  /**
   * @param cacheName the cacheName to set
   */
  public void setCacheName(String cacheName) {
    this.cacheName = cacheName;
  }

  /**
   * @return the stub
   */
  public boolean isStub() {
    return stub;
  }

  /**
   * @param stub the stub to set
   */
  public void setStub(boolean stub) {
    this.stub = stub;
  }

  /**
   * @return the irodsRoot
   */
  /*public String getIrodsRoot() {
    return irodsRoot;
  }*/

  /**
   * @param irodsRoot the irodsRoot to set
   */
  /*public void setIrodsRoot(String irodsRoot) {
    this.irodsRoot = irodsRoot;
  }*/

  /**
   * @return the urlPrefix
   */
  /*public String getUrlPrefix() {
    return urlPrefix;
  }*/

  /**
   * @param urlPrefix the urlPrefix to set
   */
  /*public void setUrlPrefix(String urlPrefix) {
    this.urlPrefix = urlPrefix;
  }*/

  /**
   * @return the tempFileFolder
   */
  public String getTempFileFolder() {
    return tempFileFolder;
  }

  /**
   * @param tempFileFolder the tempFileFolder to set
   */
  public void setTempFileFolder(String tempFileFolder) {
    this.tempFileFolder = tempFileFolder;
  }

  /**
   * @return the batchSize
   */
  public int getBatchSize() {
    return batchSize;
  }

  /**
   * @param batchSize the batchSize to set
   */
  public void setBatchSize(int batchSize) {
    this.batchSize = batchSize;
  }
}